package emulator.unittest.hardware.nmos6502.commands;

import static org.junit.Assert.*;

import org.junit.Test;

import emulator.EmulatorException;
import emulator.hardware.HwByte;
import emulator.hardware.HwWord;
import emulator.hardware.clock.ClockImplementation;
import emulator.hardware.memory.MemoryBlock;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.Flags6502;
import emulator.hardware.nmos6502.commands.BRK;
import emulator.hardware.nmos6502.operands.NoOperand;

public class BRKTest {

	@Test
	public void testExecute() throws EmulatorException {
		Cpu6502 cpu = new Cpu6502();
		MemoryBlock memory = new MemoryBlock(65536);
		memory.write(0xFFFE, 0xD2);
		memory.write(0xFFFF, 0xFF);
		ClockImplementation clock = new ClockImplementation();
		cpu.attach(memory, clock);
		cpu.setPC(0x1A2B);
		cpu.setSP(new HwByte(0xFF));

		BRK brk = new BRK();
		brk.execute(cpu, new NoOperand());
		assertEquals(new HwByte(0xFC), cpu.getSP());
		assertEquals(new HwWord(0xFFD2), cpu.getPC());
		assertEquals(0x1A, memory.read(0x1FF));
		assertEquals(0x2C, memory.read(0x1FE));
		assertEquals(new Flags6502(Flags6502.FLAG_BREAK), new HwByte(memory.read(0x1FD)));
	}

}
